export default {
  data() {
    return {
      loginname: '', //用户登陆状态
      activeIndex: '' //头部导航的激活链接
    }
  },
 async created() { //页面渲染后  对应点击导航条选项高亮
    this.activeIndex = window.sessionStorage.getItem("active"); //获取对应的高亮下标位置
    //window.sessionStorage.setItem('user', JSON.stringify('{username:"adas"}'));
    // window.sessionStorage.removeItem("user");
   // const user = JSON.parse(window.sessionStorage.getItem('user')) //获取客户端存储的用户
    const {
      data: user
    } = await this.$axios.post('UserController/getUser.action');
    console.log(user + 'user');
    if (user) {
      this.loginname = user.username; //给头部的登陆和注册导航判断
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      // console.log(key, keyPath);
    },
    //登陆页
    toNext(url) {
      window.sessionStorage.setItem("active", url);
      this.activeIndex = url;
    },
    //退出登陆
    async loginOut(url) {
      //后端退出登陆
      const {
        data: res
      } = await this.$axios.post('UserController/outLogin.action')
      //前端退出登陆
      //清除用户信息和注册时保存的电话号码
      window.sessionStorage.removeItem("user");
      window.sessionStorage.setItem("active", url)
      this.activeIndex = url;
      // this.$router.push('/login') // 重定向到登陆页
    }
    //method结束
  }
}
